//
//  ProductCell.m
//  UI Demo
//
//  Created by Rainy Zou on 15/11/30.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "ProductCell.h"
#import "Product.h"
#import "ProductFrame.h"


@interface ProductCell()
@property (nonatomic, weak) UIImageView *image;
@property(nonatomic, weak)UILabel *name;
@property(nonatomic,weak)UILabel *price;

@end

@implementation ProductCell

-(void)setPframe:(ProductFrame *)pframe
{
    _pframe = pframe;
    Product *p = pframe.product;
    
    self.image.frame = pframe.imageF;
    self.name.frame = pframe.nameF;
    self.price.frame = pframe.priceF;
    
    [self.image setImage:[UIImage imageNamed:p.image]];
    [self.name setText:p.name];
    [self.price setText:[NSString stringWithFormat:@"价格：￥%.2f",p.price]];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self == [super initWithFrame:frame])
    {
        UIImageView *imageView = [[UIImageView alloc]init];
        
        CALayer *layer = imageView.layer;
        layer.borderColor = [[UIColor blackColor] CGColor];
        layer.borderWidth = 1;
        layer.shadowOffset = CGSizeMake(4, 4);
        layer.shadowOpacity = 0.5;
        layer.shadowRadius = 10;
        
        UILabel *nameView = [[UILabel alloc]init];
        nameView.numberOfLines = 0;
        nameView.font = [UIFont systemFontOfSize:FONTSIZE];
        nameView.textAlignment=NSTextAlignmentCenter;
        UILabel *priceView = [[UILabel alloc]init];
        priceView.font = [UIFont systemFontOfSize:FONTSIZE];
        priceView.numberOfLines = 0;
        
        self.image = imageView;
        self.name = nameView;
        self.price = priceView;
        
        
        [self addSubview:imageView];
        [self addSubview:nameView];
        [self addSubview: priceView];
    }
    return self;
}


@end
